package com.corpgovernment.common.enums;

import java.util.EnumSet;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

/**
 * 产线枚举
 *
 * @author wangyujue
 */
public enum SiteEnum {
    FLIGHT("flight", "国内机票", "flight"),
    TRAIN("train", "火车票", "train"),
    HOTEL("hotel", "国内酒店", "hotel"),
    CAR("car", "用车", "car"),
    FLIGHTINTL("flightintl", "国际机票", "intlflight"),
//    //2024-01-10 增加此枚举是因为mb_supplier_company表中存储的product_type为intlflight
//    //而上个枚举无法匹配导致NPE 但又无法确认上个枚举是否被其他业务使用 故新增此枚举
//    2024-03-25 由于增加该枚举导致前端显示错误 故去除新增枚举 增加alias字段匹配
//    bug地址 https://idev.ctripcorp.com/home/prod-defect?selectedcard=3896138&productid=10001395
//    INTLFLIGHT("intlflight", "国际机票", ""),

	HOTELINTL("hotelintl", "海外酒店","hotelintl"),
	AIRPORTTRANSFER("airportTransfer","接送机", "airportTransfer"),
	TRAINTRANSFER("trainTransfer","接送站", "trainTransfer"),
	OTHER("other", "其他", "other");

    private String code;
    private String desc;

    private String alias;

    SiteEnum(String code, String desc, String alias) {
        this.code = code;
        this.desc = desc;
        this.alias = alias;
    }

    public String getCode() {
        return code;
    }
    private static final Map<String, SiteEnum> lookup = new HashMap<>();

    private static final Map<String, SiteEnum> aliasLookup = new HashMap<>();


    static {
        for (SiteEnum s : EnumSet.allOf(SiteEnum.class)) {
            lookup.put(s.getCode(), s);
            aliasLookup.put(s.getAlias(), s);
        }
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getDesc() {
        return desc;
    }

    public void setDesc(String desc) {
        this.desc = desc;
    }

    public String getAlias() {
        return alias;
    }

    public void setAlias(String alias) {
        this.alias = alias;
    }

    public static SiteEnum get(String code) {
        return lookup.get(code);
    }
    public static boolean exists(String code) {
        return lookup.containsKey(code);
    }

    /**
     * 首先根据code匹配siteEnum 若不存在则根据alias匹配siteEnum
     * @param code
     */
    public static SiteEnum getByCodeThenAlias(String code) {
        SiteEnum siteEnum = lookup.get(code);
        if (Objects.nonNull(siteEnum)) {
            return siteEnum;
        }
        return aliasLookup.get(code);
    }
}
